window.onload = function() {
  //#region 点击左侧按钮打开下拉菜单
  // 获取一级菜单里面的a标签
  const aList = document.querySelectorAll(".nav>li>a");
  
  // console.log(aList);
  //给每个一级菜单的a添加点击事件
  aList.forEach(aDom=>aDom.addEventListener("click",function() {
    
    //点击以后兄弟元素添加一个类
    this.nextElementSibling.classList.toggle("show");

  }))

  //获取二级菜单
  const subList = document.querySelectorAll(".nav ul a");
  subList.forEach(aDom=>aDom.addEventListener("click",function() {
    //先让所有的二级菜单A标签拥有这个类的移除掉
    // 再给点击的a标题添加这个类
    document.querySelector(".nav ul a.active").classList.remove("active");
    this.classList.add("active");
  }))

  //#endregion

  //#region 点击三条杠隐藏/显示左侧菜单
  const menu = document.querySelector(".menu");
  menu.addEventListener("click",function() {
    document.querySelector(".leftside").classList.toggle("w0")

  })
  //#endregion

  //#region 初始化数据
  const initBtn = document.querySelector(".init")
  initBtn.addEventListener("click",function() {
    console.log("准备初始化");
    axios.get("/init/data",{}).then(result=>{
      console.log(result);
    })
  })
  //#endregion


  //#region 点击退出
  const out = document.querySelector(".logout");
  out.addEventListener("click",function() {
    if (confirm("你确定要退出么？崽子")) {
      localStorage.removeItem("token");
      location.href = './login.html';
    }
  })
  //#endregion

  //#region 页面打开就初始化数据
  getInitData();
  function getInitData() {
    axios.get("/student/list",{}).then(result=>{
      // console.log(result);
    })
  }
  //#endregion
}